<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="stylesheet" href="../css/common.css">
    <style>
         html,body,header,section,footer,nav,div,ul,ol,li,img,a,span,em,del,center,strong,var,fieldset,form,label,dt,dd,cite,input,hr,time,mark,code,figcaption,figure,textarea{
            margin:0;
            border:0;
            padding:0;
        }
        html,body {
            -webkit-touch-callout:none;
            -webkit-text-size-adjust:none;
            -webkit-tap-highlight-color:rgba(0, 0, 0, 0);
            -webkit-user-select:none;
        }

        header,footer,section,nav,img,a,button,em,del,strong,var,fieldset,label,cite,small,time,mark,code,figcaption,figure,textarea{
            display:block;
        }
        header,section,footer,nav {
            position:relative;
            overflow:hidden;
        }
        ol,ul{
            list-style:none;
        }
        input,button,textarea {
            border:0;
            margin:0;
            padding:0;
            font-size:1em;
            line-height:1em;
            -webkit-appearance:none;
            background-color:rgba(0, 0, 0, 0);
        }
        span{
            display:inline-block;
        }
        a,a:visited{
            text-decoration:none;
        }

        #header {
            background-color:#40aa53;
        }
        #nav{
            display:-webkit-box;
            height:40px;
        }
        #left {
            width:80px;
            color:#fff;
            background:url(../image/navbtn_back.png) no-repeat 14px 12px;
            -webkit-background-size:12px 20px;
        }
        #left>span {
            margin-top:13px;
            margin-left:36px;
            font-size:18px;
            height:18px;
            line-height:18px;
        }
        #middle {
            -webkit-box-flex:1;
            width:100%;
            display:-webkit-box;
            -webkit-box-pack:center;
            -webkit-box-align:center;
        }
        #title {
        	font-size: 20px; height: 44px; margin: 0em; color: #fff;
            line-height:40px;
            -webkit-box-flex: 1;
            -webkit-flex: 1;
            flex: 1;
            text-align: center;
        }
        #right {
            width:80px;
        }
        section {
            -webkit-box-flex:1;
        }
        #footer {
            width: 100%;
            height:50px;
            background-color: #FFFFFF;
        }
    </style>
</head>
<body>
<div id="wrap">
    <header id='header'>
        <nav id="nav">
            <a tapmode="" id="left" onclick="closeWin();">
                <span>返回</span>
            </a>
            <div id="middle" tapmode="" onclick="gotop('frm_comment')">
                <div id="title">跟帖</div>
            </div>
            <a id="right">
            </a>
        </nav>
    </header>
    <div id="main">
    </div>
    <div id="footer">
    </div>
</div>
</body>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script>
var fid,tid,title;

apiready = function() {
	var pageParam = api.pageParam;
	fid = pageParam.fid;
	tid = pageParam.tid;
	title = pageParam.title;
	
    var header = $api.byId('header');
    var body = $api.dom('body');
    var footer = $api.byId('footer');
    
    $api.fixIos7Bar(header);
    
    var header_h = $api.offset(header).h;
    var body_h = $api.offset(body).h;
    var footer_h = $api.offset(footer).h;
    var rect_h = body_h - header_h - footer_h;

    api.openFrame({
        name: 'frm_comment',
        url: 'frm_comment.html',
        rect:{
            x:0,
            y:header_h,
            w:'auto',
            h:rect_h
        },
        bounces: true,
        pageParam: pageParam,
    });
    
	writeComment();
}

function closeWin(){
	api.closeWin();
}

// 直接写评论
function writeComment(reply_author, pid, floor){
	if(window.isOpenChatBox){
	    closeInputField();
	}

    if(arguments.length === 0){
		var reply_title = 'Re:'+title;
		var action = 'reply';
		var article = '';
		var placeholder = '说点什么';
    }else{
    	var reply_author = unescape(reply_author);
    	var reply_title = '回 '+floor+'樓('+reply_author+') 的帖子';
    	var action = 'quote';
    	var article = floor;
    	var placeholder = '回覆 '+reply_author+'：';
    }

	var chatBox = api.require('chatBox');
	chatBox.open({
	    switchButton:{
	        "faceNormal": "widget://image/chatBox/face1.png",
	        "faceHighlight": "widget://image/chatBox/face2.png",
	        "addNormal": "widget://image/chatBox/add1.png",
	        "addHighlight": "widget://image/chatBox/add2.png",
	        "keyboardNormal": "widget://image/chatBox/key1.png",
	        "keyboardHighlight": "widget://image/chatBox/key2.png"
	    },
	    sourcePath:"widget://image/chatBox/emotion",
		placeholder: placeholder,
		maxLines: 4,
	    addButtons: [
	        {
	            "normal": "widget://image/chatBox/cam1.png",
	            "highlight": "widget://image/chatBox/cam2.png",
	            "title": "图片"
	        },
	        {
	            "normal": "widget://image/chatBox/loc1.png",
	            "highlight": "widget://image/chatBox/loc2.png",
	            "title": "位置"
	        }
	    ]
	},function(ret,err) {
		if(ret.click){
		    //api.alert({msg:"用户点击了第"+ret.index+"个按钮"});
			api.toast({
			    msg: '暫時不支持此功能',
			    duration:2000,
			    location: 'middle'
			});
		}else{
			var uid = $api.getStorage('uid');
			if("undefined" == typeof uid){
				api.toast({
				    msg: '請先登錄',
				    duration:2000,
				    location: 'middle'
				});
				return false;
			}
		
			// 由于中文编码问题未解决，暂不支持回帖
			api.toast({
			    msg: '暫時不支持回帖',
			    duration:2000,
			    location: 'middle'
			});
			return false;
	
			if(ret.msg.length < 1){
				api.alert({
				    msg: '請填寫內容',
				},function(ret,err){
				});
				return false;
			}

			api.showProgress({
			    style: 'default',
			    animationType: 'fade',
			    title: '提交中',
			    modal: false
			});

			api.ajax({
				url: OpenAPI.post,
				method: 'POST',
				timeout: 30,
				dataType: 'text',
				charset: 'gbk',
				data:{
					values: {
						atc_usesign: 1,
						atc_convert: 1,
						atc_autourl: 1,
						atc_title: 'Re:'+reply_title,
						atc_content: ret.msg,
						step: 2,
						action: action,
						fid: fid,
						tid: tid,
						atc_attachment: 'none',
						pid: '',
						article: '',
						verify: 'verify',
					},
				},
				returnAll:true,
			},function(ret,err){


				api.hideProgress();
				if (parseInt(ret.statusCode) == 200) {
					var rgexp1 = /發貼完畢點擊進入主題列表/;
					var rgexp2 = /您還不是論壇會員,請先登錄論壇/;
					var rgexp3 = /<center><br \/><br \/><br \/>(.+)<br \/>/;
					//var rgexp4 = /讀取數據錯誤,原因：您要訪問的鏈接無效,可能鏈接不完整,或數據已被刪除!/;
				    if (rgexp1.test(ret.body)) {	// 發貼完畢
						api.toast({
						    msg: '發貼完畢',
						    duration:2000,
						    location: 'middle'
						});
						closeInputField();
				    }else if (rgexp2.test(ret.body)) {	// 您還不是論壇會員,請先登錄論壇
						api.toast({
						    msg: '您還不是論壇會員,請先登錄論壇',
						    duration:2000,
						    location: 'middle'
						});
				    	$api.rmStorage('uid');
				    	$api.rmStorage('username');
				    	$api.rmStorage('groupname');
						api.execScript({
						    name: 'fixed',
						    script: 'setUserInfo();'
						});
				    }else if (rgexp3.test(ret.body)) {	// 其他提示
					var  mMsg = ret.body.match(/<center><br \/><br \/><br \/>(.+)<br \/>/);
					var msg = mMsg[1];
				    
						api.toast({
						    msg: msg,
						    duration:2000,
						    location: 'middle'
						});
				    }
				    
				    
				}else{
					showErrMgs(err.code, err.msg);
				}

			});
		
		}

	});
	window.isOpenChatBox = true;
}

function closeInputField(){
	var chatBox = api.require('chatBox');
	    chatBox.close();
}
</script>
</html>